# 碰壁反弹
import pygame
import sys

pygame.init()

WINX = 300
WINY = 300
screen = pygame.display.set_mode((WINX, WINY))
fclock = pygame.time.Clock()
x = 100
y = 100
speedx = 1
speedy = 1
while True:
    for e in pygame.event.get():
        if e.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        # elif e.type == pygame.KEYDOWN:
        #     if e.key == pygame.K_DOWN:
        #         print('keydown')
    screen.fill((0, 0, 0))
    pygame.draw.rect(screen, (62, 134, 160), (x, y, 90, 90))
    pygame.display.update()
    if x >= WINX - 90 or x<=0:
        speedx *= -1
    if y >= WINY - 90 or y<=0:
        speedy *= -1

    x += speedx
    y+=speedy
    # if d == '未碰':
    #     x += speedx
    # elif d == '已碰右':
    #     x -= speedx
    # elif d == '已碰左':
    #    x += speedx
    fclock.tick(25)
